package cc.iits.demo.crane.api.vo;

import com.alibaba.fastjson.JSON;

import java.util.HashMap;

/**
 * 通用请求
 * @author 易俊
 */
public class RestRequest extends HashMap<String,Object> {

    private final static String PAGE_NAME="page";
    private final static String ROWS_NAME="rows";
    private final static String INPUT_NAME="input";
    private final static String FIELD_NAME="field";

    public int getPage() {
        return this.containsKey(PAGE_NAME)?(int)this.get(PAGE_NAME):0;
    }

    public int getRows() {
        return this.containsKey(PAGE_NAME)?(int)this.get(ROWS_NAME):0;
    }

    public String getInput() {
        return (String) this.get(INPUT_NAME);
    }

    public String getField() {
        return (String) this.get(FIELD_NAME);
    }


    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    public static RestRequest parseJson(String json){
        return JSON.parseObject(json, RestRequest.class);
    }
}
